﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FJERP.BLL;
using FJERP.Model;
using System.Data;

namespace FJERP.Handler
{
    /// <summary>
    /// Purcachase 的摘要说明
    /// </summary>
    public class Purcachase : IHttpHandler
    {
        PurchaseBLL bll = new PurchaseBLL();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"].ToString();
            System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(action);
            if (methodInfo != null)
            {
                methodInfo.Invoke(this, new object[] { context });
            }
        }
        public void IntoMate(HttpContext context)
        {
            int id = Convert.ToInt32(context.Request["id"]);
            List<PurchaseMate> list = bll.PurCheckMate(id);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void IntoWarehouse(HttpContext context)
        {
            int id = Convert.ToInt32(context.Request["id"]);
            context.Response.Write(bll.IntoStock(id));
        }
        public void IntoSearch(HttpContext context)
        {
            PurchaseBLL bll = new PurchaseBLL();
            string Product_Modelspe = context.Request["Product_Modelspe"];
            List<FJERP.Model.Product> list = bll.SearchProductByModelspe(Product_Modelspe);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void IntoList(HttpContext context)
        {
            Purchase p = new Purchase();
            p.Supplier_Id = Convert.ToInt32(context.Request["Supplier_Id"]);
            p.WareHose_Id = Convert.ToInt32(context.Request["WareHose_Id"]);
            p.Employee_Id = Convert.ToInt32(context.Request["Employee_Id"]);
            p.SumMoney = Convert.ToInt32(context.Request["SumMoney"]);
            p.Purchase_State = 0;
            p.PurChase_InOut = "采购";
            string xml = context.Server.UrlDecode(context.Request.Form["xml"].ToString());  //xml解码
            context.Response.Write(bll.Purchase_IntoList(p, xml));
        }
        public void Out_Show(HttpContext context)
        {
            string Product_Modelspe = context.Request["Product_Modelspe"];
            DataTable data = bll.Product_Sel(Product_Modelspe);
            List<FJERP.Model.Product> list = new List<FJERP.Model.Product>();
            foreach (DataRow item in data.Rows)
            {
                FJERP.Model.Product P = new FJERP.Model.Product();
                P.Product_Id = Convert.ToInt32(item["Product_Id"]);
                P.Product_Barcode = item["Product_Barcode"].ToString();
                P.Product_Bprid = Convert.ToDecimal(item["Product_Bprid"]);
                P.Product_frim = item["Product_frim"].ToString();
                P.Product_Modelspe = item["Product_Modelspe"].ToString();
                P.Product_Name = item["Product_Name"].ToString();
                P.Product_Price = Convert.ToDecimal(item["Product_Price"]);
                P.Product_Remark = item["Product_Remark"].ToString();
                P.Product_Type_Name = item["Product_Type_Name"].ToString();
                P.Product_Unit_Id = item["Product_Unit_Id"].ToString();
                list.Add(P);
            }
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void Out_SEL(HttpContext context)
        {
            PurchaseOutBLL bll = new PurchaseOutBLL();
            int id = Convert.ToInt32(context.Request["id"]);

            List<PurchaseMate> list = bll.Purchase_pal(id);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void Out_SEL1(HttpContext context)
        {
            PurchaseOutBLL bll = new PurchaseOutBLL();
            int id = Convert.ToInt32(context.Request["id"]);
            List<Purchase> list = bll.Purchase_palauat(id);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void Out(HttpContext context)
        {
            PurchaseOutBLL bll = new PurchaseOutBLL();
            int id = Convert.ToInt32(context.Request["id"]);
            context.Response.Write(bll.Product_Sate(id));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}